﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using ApartmentBillsManager.Start.Common;

namespace ApartmentBillsManager.Start.Converters
{
    class CategoryToHebrewConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is BillCategory)
            {
                switch ((BillCategory)value)
                {
                    case BillCategory.Electricity:
                        return "חשמל";
                    case BillCategory.Gas:
                        return "גז";
                    case BillCategory.Groceries:
                        return "קניות";
                    case BillCategory.InternetInfra:
                        return "תשתית אינטרנט";
                    case BillCategory.InternetProvider:
                        return "ספק אינטרנט";
                    case BillCategory.PropertyTax:
                        return "ארנונה";
                    case BillCategory.Water:
                        return "מים";
                }
            }

            if (value is IEnumerable)
            {
                var billCategories = value as IEnumerable;

                var hebrewCategories = new List<string>();

                foreach (var category in billCategories)
                {
                    if (category is BillCategory)
                    {
                        switch ((BillCategory)category)
                        {
                            case BillCategory.Electricity:
                                hebrewCategories.Add("חשמל");
                                break;
                            case BillCategory.Gas:
                                hebrewCategories.Add("גז");
                                break;
                            case BillCategory.Groceries:
                                hebrewCategories.Add("קניות");
                                break;
                            case BillCategory.InternetInfra:
                                hebrewCategories.Add("תשתית אינטרנט");
                                break;
                            case BillCategory.InternetProvider:
                                hebrewCategories.Add("ספק אינטרנט");
                                break;
                            case BillCategory.PropertyTax:
                                hebrewCategories.Add("ארנונה");
                                break;
                            case BillCategory.Water:
                                hebrewCategories.Add("מים");
                                break;
                        }
                    }
                }
                return hebrewCategories;
            }

            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string)
            {
                switch ((string)value)
                {
                    case "חשמל": return BillCategory.Electricity;
                    case "גז": return BillCategory.Gas;
                    case "קניות": return BillCategory.Groceries;
                    case "תשתית אינטרנט": return BillCategory.InternetInfra;
                    case "ספק אינטרנט": return BillCategory.InternetProvider;
                    case "ארנונה": return BillCategory.PropertyTax;
                    case "מים": return BillCategory.Water;
                }
            }

            return null;
        }
    }
}
